package es.techideas.appsjam.model;

import android.content.Context;
import es.techideas.appsjam.GameView;
import es.techideas.appsjam.R;

public class ContainerModelElement extends AbstractModelElement{

	public ContainerModelElement(Context context, GameView view, ContainerColor cc) {
		super(context, view, cc);
	}

	@Override
	public void initialize(){
		super.initialize();
		setPositionDependingOnContainer();
	}
	
	@Override
	public void setHeight(double h){
		super.setHeight(287/2);
	}
	
	@Override
	public void setWidth(double w){
		super.setWidth(192/2);
	}

	private void setPositionDependingOnContainer() {
		setX(getCanvasWidth() - getWidth()/2 -getCanvasWidth() * 35.0 / 100.0);
		double pos = 0;
		switch(getContainerColor()){
		case VIDRE:
			pos += getHeight();
			break;
		case PLASTICS:
			pos += getHeight()*2;
			break;
		case RESTA:
			pos += getHeight()*3;
			break;
		case PAPER:
			pos += getHeight()*4;
			break;
		case ORGANIC:
			pos += getHeight()*5;
			break;
		case PUNT_VERD:
			pos += getHeight()*6;
			break;
		}
		setY(pos);

	}

	protected int getDrawableId() {
		switch(getContainerColor()){
		case VIDRE:
			return R.drawable.vidres_container;
		case PLASTICS:
			return R.drawable.plastics_container;
		case RESTA:
			return R.drawable.resta_container;
		case PAPER:
			return R.drawable.paper_container;
		case ORGANIC:
			return R.drawable.organic_container;
		default:
			return R.drawable.puntverd_container;
		}
	}

	public boolean contains(AbstractModelElement element) {
		if(element.getLeft() > getLeft()){
			if(getContainerColor() == ContainerColor.PUNT_VERD){
				if(element.getY() >= getBottom()){
					return true;
				}
			}
			if(getContainerColor() == ContainerColor.VIDRE){
				if(element.getY() <= getTop()){
					return true;
				}
			}
			if(element.getY() >= getTop() && element.getY() <= getBottom()){
				return true;
			}
		}
		return false;
	}
}

